home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 283_01 / oldedits.c < prev    next >
C/C++ Source or Header  |  1988-08-27  |  9KB  |  291 lines

  1.  
  2. /* oldedits.c, david c. oshel, 11/22/86
  3. ** 4/23/88, d.c.o, removed signal code, doesn't belong in service routines
  4. ** 8/29/88, d.c.o. formerly MONEY.C, rearranged old editing routines to
  5. **                 avoid linking them when not called for
  6. */
  7.  
  8. #include <stdarg.h>
  9. #include "ciao.h"
  10. #include "keys.h"
  11.  
  12. #define MINUS '-'
  13.  
  14. /* edit interrupt flags
  15. */
  16.  
  17. int ESCflag = 0, MINUSflag = 0;
  18.  
  19. /* edit masked numeric
  20. ** may only edit digits in the self-masking string, can't delete
  21. ** skips over (forward or backward) any edit character not a digit
  22. ** calls Function Key handler if user enters one
  23. ** the called Fn function is responsible for screen condition!
  24. ** returns 0 if successful 
  25. ** returns ESC if user interrupts with ESC and ESCflag is non-zero
  26. */
  27.  
  28. int edit_masked_numeric( buffptr, fnkey )
  29. char *buffptr;
  30. void (* fnkey)();
  31. {
  32.      static char *p; 
  33.      static int ch;
  34.      int len;
  35.  
  36.      /* highlight string to be edited */
  37.  
  38.      wprintf( "^2%s", buffptr );
  39.      len = strlen( buffptr );
  40.      for (ch = 0; ch < len; ch++ ) wink( '\b' );
  41.  
  42.      p = buffptr;
  43.      while (*p)
  44.      {
  45.          if ( isdigit( *p ) ) 
  46.          {
  47.               odd:  ch = getkey();
  48.               switch (ch)
  49.               {
  50.               case ESC:{ if (ESCflag != 0) return (ESC); break; }
  51.               case CR: { /* accept entry */
  52.                        while (*p) wink( *p++ );
  53.                        continue;
  54.                        break;
  55.                        }
  56.               case BS:
  57.               case LF:{ /* left arrow */
  58.                        if (p > buffptr)
  59.                        {
  60.                           do
  61.                           {
  62.                              --p;
  63.                              wink( '\b' );
  64.                           }
  65.                           while ( (!isdigit( *p )) && (p > buffptr) );
  66.                        }
  67.                        continue;
  68.                        break;
  69.                        }
  70.               case RT:{ /* right arrow */
  71.                        wink( *p++ );
  72.                        continue;
  73.                        break;
  74.                        }
  75.               case F1:
  76.               case F2:
  77.               case F3:
  78.               case F4:
  79.               case F5:  /* was input a Fn key? */
  80.               case F6:
  81.               case F7:
  82.               case F8:
  83.               case F9:
  84.               case F10:{
  85.                        (* fnkey)( ch );
  86.                        continue;
  87.                        break;
  88.                        }
  89.               default: if ( isascii( ch ) && isdigit( ch ) )
  90.                        ;
  91.                        else { thurb(); goto odd; }
  92.               }
  93.          }
  94.          else ch = *p;        /* not digit mask, accept entry from buffptr */
  95.  
  96.          *p = ch;             /* put char in buffptr */
  97.          wink( *p++ );        /* echo it */
  98.  
  99.      }
  100.  
  101.      /* display string as edited, normal vid mode */
  102.  
  103.      for (ch = 0; ch < len; ch++ ) wink( '\b' );
  104.      wprintf( "^0%s", buffptr );
  105.      return ( 0 );
  106. }
  107.  
  108.  
  109.  
  110.  
  111. /* Edit String.
  112. ** calls Function Key handler if user enters one
  113. ** the called Fn function is responsible for screen condition!
  114. ** returns ESC if user interrupts with ESC and ESCFlag is nonzero
  115. ** returns MINUS if user interrupts with MINUS and MINUSFlag is nonzero
  116. ** returns 0 otherwise 
  117. */
  118.  
  119. int edit_string( buffptr, fnkey )
  120. char *buffptr;
  121. void (* fnkey)();
  122. {
  123.      static char *p; 
  124.      static int ch;
  125.      int len;
  126.  
  127.      /* highlight string to be edited */
  128.  
  129.      wprintf( "^2%s", buffptr );
  130.      len = strlen( buffptr );
  131.      for (ch = 0; ch < len; ch++ ) wink( '\b' );
  132.  
  133.      p = buffptr;
  134.      while (*p)
  135.      {
  136.           ch = getkey();
  137.           if ( isascii( ch ) )
  138.           {
  139.              switch (ch)
  140.              {
  141.              case ESC:{ if (ESCflag != 0) return (ESC); break; }
  142.              case CR:{
  143.                       /* CR, accept input & exit */
  144.                       while (*p) wink( *p++ );
  145.                       break;
  146.                       }
  147.              case BS:{                        /* backspace */
  148.                       if (p > buffptr)
  149.                       {
  150.                          --p;
  151.                          wink( '\b' );
  152.                       }
  153.                       break;
  154.                       }
  155.              case '-':{ if (MINUSflag != 0) return (MINUS); /* NO BREAK */ } 
  156.              default: {
  157.                       if ( isgraph( ch ) || ch == 0x20 ) 
  158.                       { 
  159.                           *p = ch;              /* put char in buffptr */
  160.                           wink( *p++ );         /* echo it */
  161.                       }
  162.                       else 
  163.                       {
  164.                           thurb();              /* reject unprintables */
  165.                       }
  166.                       break;
  167.                       }
  168.              }
  169.           }
  170.           else
  171.           {
  172.              switch (ch)
  173.              {
  174.              case F1:
  175.              case F2:
  176.              case F3:
  177.              case F4:
  178.              case F5:  /* was input a function key? */
  179.              case F6:
  180.              case F7:
  181.              case F8:
  182.              case F9:
  183.              case F10:{
  184.                       (* fnkey)( ch );
  185.                       break;
  186.                       }
  187.              case LF:{                         /* left arrow */
  188.                       if (p > buffptr)
  189.                       {
  190.                          --p;
  191.                          wink( '\b' );
  192.                       }
  193.                       break;
  194.                       }
  195.              case RT:{                         /* right arrow */
  196.                       wink( *p++ );
  197.                       break;
  198.                       }
  199.              default: {
  200.                       thurb();
  201.                       break;
  202.                       }
  203.              }
  204.           }
  205.      }
  206.  
  207.      /* display string as edited, normal vid mode */
  208.  
  209.      for (ch = 0; ch < len; ch++ ) wink( '\b' );
  210.      wprintf( "^0%s", buffptr );
  211.      return ( 0 );
  212. }
  213.  
  214.  
  215.  
  216. /*========================================*/
  217. /*  getms(p, maxinput, wait, esc)         */
  218. /*  Simple getline function with special  */
  219. /*  input handling,  1 <= len <= maxinput */
  220. /*========================================*/ 
  221.  
  222. int getms( p, maxinput, wait, esc ) 
  223. char *p; 
  224. int maxinput; 
  225. void (* wait)();
  226. void (* esc)();
  227. {
  228.    static int len;
  229.    static int ch;
  230.  
  231.    len = -1;
  232.    if (maxinput < 1 || maxinput > 79) maxinput = 79;
  233.  
  234.    while (1)
  235.    {
  236.         ch = keyin( wait );  
  237.  
  238.         if (len < 0) len = 0;       /* don't destroy prompt by backing up */
  239.  
  240.         if (ch == '\n' || ch == '\r') 
  241.         {                           /* end of line?  don't store newline */
  242.                 *p = '\0';          /* mark it with a B for baby and me  */
  243.                 break;              /* and break out of while loop       */
  244.         }
  245.  
  246.         else if ((ch == '\b') || (ch == 127)) 
  247.         {                                /* backspace? rubout?  */
  248.                 if (len-- > 0) 
  249.                 {
  250.                         wink(127);       /* destructive bs      */
  251.                         p--;             /* delete from string  */
  252.                 }
  253.         }
  254.  
  255.         /*--------------------------------*/
  256.         /* SPECIAL ROUTINE FOR ESCAPE KEY */
  257.         /*--------------------------------*/
  258.  
  259.         else if (ch == '\033') 
  260.         {                                /* do ESC function */
  261.                 (* esc)();               /* routinely contains a longjmp */
  262.         }
  263.  
  264.         else if (ch == '\025' || ch == '\030') 
  265.         {                                /* Ctl-U, Ctl-X */
  266.                 while (len--) 
  267.                 {
  268.                         p--;
  269.                         wink(127);
  270.                 }
  271.         }
  272.         else if (len == maxinput) 
  273.         {                                /* test specials before testing len */
  274.                 bell();
  275.         }
  276.         else if (ch > 31 && ch < 127) 
  277.         {                                /* printable ch